{extend name="../../base/view/common/base" /}
{block name="body"}
<form class="layui-form p-4">
    <table class="layui-table layui-table-form">
        <tr>
            <td colspan="6"><strong>上报信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray">上报时间</td>
            <td colspan="3">
                <input type="text" name="report_date" id="report_date" lay-reqText="上报时间" placeholder="上报时间"
                       class="layui-input" value="{$detail.report_date}">
            </td>
        </tr>
        <tr id="flow_tr">
            <td class="layui-td-gray">上报人</td>
            <td>
                <input type="text" name="report_name" value="{$detail.report_name}" autocomplete="off"
                       placeholder="请选择上报人" lay-reqText="上报人" class="layui-input picker-one" readonly><input
                    type="hidden" name="report_id" value="{$detail.report_id}" readonly>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">上报次数</td>
            <td colspan="3">
                <input type="number" name="report_num" lay-reqText="上报次数" placeholder="上报次数"
                       class="layui-input" value="{$detail.report_num}">
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">上报状态</td>
            <td>
                <select name="report_status" lay-reqText="请选择上报状态" lay-filter="report_status">
                    <option value=""
                    <?php if($detail['report_status'] == '') echo 'selected' ?>>请选择上报状态</option>
                    <option value="0"
                    <?php if($detail['report_status'] == '0') echo 'selected' ?>>待上报</option>
                    <option value="1"
                    <?php if($detail['report_status'] == '1') echo 'selected' ?>>已上报</option>
                    <option value="2"
                    <?php if($detail['report_status'] == '2') echo 'selected' ?>>审核中</option>
                    <option value="3"
                    <?php if($detail['report_status'] == '3') echo 'selected' ?>>已公示</option>
                </select>
            </td>
        </tr>
        <tr id="deduct">
            {if $detail.report_status eq 3}
            <td class="layui-td-gray">提成金额</td>
            <td>
                <input type="number" name="deduct" value="{$detail.deduct}" autocomplete="off"
                       lay-reqText="提成金额" placeholder="提成金额" class="layui-input">
            </td>
            {/if}
        </tr>
        <tr>
            <td class="layui-td-gray">公示时间</td>
            <td colspan="3">
                <input type="text" name="gs_date" id="gs_date" lay-reqText="公示时间" placeholder="公示时间"
                       class="layui-input" value="{$detail.gs_date}">
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>附件信息</strong></td>
        </tr>
        <tr>
            <td colspan="5" style="line-height:inherit">
                <div class="layui-row" id="fileBox">
                    <input type="hidden" data-type="file" name="file_ids" value="{$detail.file_ids}">
                    {notempty name="$detail.file_ids"}
                    {volist name="$detail.fileArray" id="vo"}
                    <div class="layui-col-md4" id="uploadImg{$vo.id}">{:file_card($vo)}</div>
                    {/volist}
                    {/notempty}
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>业务备注</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray">备注</td>
            <td >{$detail.remark}</td>
        </tr>

    </table>
    <div style="padding: 10px 0">
        <input name="cert_id" id="cert_id" type="hidden" value="{$cert_id}">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool', 'employeepicker', 'oaTool'];

    function gouguInit() {
        var form = layui.form, tool = layui.tool, table = layui.table, laydate = layui.laydate, oaTool = layui.oaTool,
            employeepicker = layui.employeepicker;

        //相关附件上传
        oaTool.addFile();

        laydate.render({
            elem: '#cert_valid_date',
            showBottom: false
        });
        laydate.render({
            elem: '#report_date',
            showBottom: false
        });
        laydate.render({
            elem: '#gs_date',
            showBottom: false
        });

        form.on("select(report_status)", function (data) {
            console.log(data.value);
            var thisValue = data.value;
            if (thisValue == '3') {
                var html = '';
                html+='<td class="layui-td-gray">提成金额</td>'
                html+='<td>';
                html+='<input type="number" name="deduct" value="" autocomplete="off" placeholder="提成金额" class="layui-input">';
                html+='</td>';
                $("#deduct").html(html);
            } else {
                $("#deduct").html("");
            }
        });
        //监听提交
        form.on('submit(webform)', function (data) {

            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    tool.sideClose(1000);
                }
            }
            tool.post("/jobproject/busine/report_add", data.field, callback);
            return false;
        });

        form.on('select(flowtype)', function (data) {
            var check_type = data.elem[data.elem.selectedIndex].title;
            var formHtml = '<td class="layui-td-gray">出证人<font>*</font></td>\
		<td colspan="5">\
			<input type="text" name="report_name" value="" autocomplete="off" placeholder="请选择上报人" lay-verify="required" lay-reqText="请选择出证人" class="layui-input picker-one"><input type="hidden" name="report_id" value="">\
		</td>';
            if (check_type == 2) {
                $('#flow_tr').html(formHtml);
                form.render();
            }
            if (data.value == '') {
                $('#flow_tr').html(formHtml);
                $('[name="copy_names"]').val('');
                $('[name="copy_uids"]').val('');
                form.render();
                return false;
            }
            $.ajax({
                url: "/api/index/get_flow_users",
                type: 'get',
                data: {id: data.value},
                success: function (e) {
                    if (e.code == 0) {
                        var flowLi = '';
                        var flow_data = e.data.flow_data;
                        if (e.data.copy_uids && e.data.copy_uids != '') {
                            $('[name="copy_names"]').val(e.data.copy_unames);
                            $('[name="copy_uids"]').val(e.data.copy_uids.split(','));
                        }
                        if (check_type == 1 || check_type == 3) {
                            for (var a = 0; a < flow_data.length; a++) {
                                var userList = '', sign_type = '';
                                if (check_type == 1) {
                                    if (flow_data[a].flow_type == 1) {
                                        userList += '<li style="padding:3px 0">当前部门负责人</li>';
                                    }
                                    else if (flow_data[a].flow_type == 2) {
                                        userList += '<li style="padding:3px 0">上级部门负责人</li>';
                                    }
                                    else {
                                        if (flow_data[a].flow_type == 3) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">或签</span>';
                                        }
                                        if (flow_data[a].flow_type == 4) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">会签</span>';
                                        }
                                        for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                            userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                        }
                                    }
                                }
                                else if (check_type == 3) {
                                    sign_type = ' <span class="layui-badge layui-bg-blue">' + flow_data[a].flow_name + '</span>'
                                    for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                        userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                    }
                                }
                                flowLi += '<li class="layui-timeline-item">\
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>\
								<div class="layui-timeline-content">\
								  <p class="layui-timeline-title"><strong>第' + (a + 1) + '级审批</strong>' + sign_type + '</p>\
								  <ul>' + userList + '</ul>\
								</div>\
							</li>';
                            }
                            formHtml = '<td class="layui-td-gray">审批流程</td>\
									<td colspan="7">\
										<ul id="flowList" class="layui-timeline">' + flowLi + '</ul>\
									</td>';
                            $('#flow_tr').html(formHtml);
                        }
                    }
                }
            })
        });



    }

</script>
{/block}